SlideShare a Scribd company logo
Class No.25  Data Structures http://ecomputernotes.com
BuildHeap The general algorithm is to place the N keys in an array and consider it to be an unordered binary tree. The following algorithm will build a heap out of N keys. for( i = N/2; i > 0; i-- ) percolateDown(i); http://ecomputernotes.com
BuildHeap i = 15/2 = 7 65 19 21 14 24 26 13 15 68 16 65 21 19 26 14 16 68 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 12 15 5 70 12 i   i Why I=n/2? http://ecomputernotes.com
BuildHeap i = 15/2 = 7 65 19 21 14 24 26 13 15 12 16 65 21 19 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 68 15 5 70 68 i   i http://ecomputernotes.com
BuildHeap i = 6 65 19 21 14 24 26 13 15 12 16 65 21 19 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 68 15 5 70 68 i   i http://ecomputernotes.com
BuildHeap i = 5 65 5 21 14 24 26 13 15 12 16 65 21 5 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i   i http://ecomputernotes.com
BuildHeap i = 4 65 5 14 21 24 26 13 15 12 16 65 14 5 26 21 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i   i http://ecomputernotes.com
BuildHeap i = 3 65 5 14 21 24 13 26 15 12 16 65 14 5 13 21 16 12 26 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i   i http://ecomputernotes.com
BuildHeap i = 2 65 16 14 21 24 13 26 15 12 32 65 14 16 13 21 32 12 26 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 5 5 12 15 4 19 13 70 14 68 15 19 70 68 i   i http://ecomputernotes.com
BuildHeap i = 1 65 16 14 21 31 24 26 15 12 32 65 14 16 24 21 32 12 26 31 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 13 13 11 5 5 12 15 4 19 13 70 14 68 15 19 70 68 i   i http://ecomputernotes.com
BuildHeap Min heap 5 16 14 21 31 24 26 15 65 32 5 14 16 24 21 32 65 26 31 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 13 13 11 12 12 12 15 4 19 13 70 14 68 15 19 70 68 http://ecomputernotes.com
Other Heap Operations decreaseKey(p, delta) :  lowers the value of the key at position ‘p’ by the amount ‘delta’. Since this might violate the heap order, the heap must be reorganized with percolate up (in min heap) or down (in max heap). increaseKey(p, delta) :  opposite of decreaseKey. remove(p) :  removes the node at position p from the heap. This is done by first decreaseKey(p, ) and then performing deleteMin(). http://ecomputernotes.com
Heap code in C++ template <class eType> class Heap { public: Heap( int capacity = 100 ); void insert( const eType & x ); void deleteMin( eType & minItem ); const eType & getMin( ); bool isEmpty( ); bool isFull( ); int Heap<eType>::getSize( ); http://ecomputernotes.com
Heap code in C++ private: int currentSize; // Number of elements in heap eType* array; // The heap array int capacity; void percolateDown( int hole ); }; http://ecomputernotes.com
Heap code in C++ #include &quot;Heap.h“ template <class eType> Heap<eType>::Heap( int capacity ) { array = new etype[capacity + 1]; currentSize=0; } http://ecomputernotes.com
Heap code in C++ // Insert item x into the heap, maintaining heap // order. Duplicates are allowed. template <class eType> bool Heap<eType>::insert( const eType & x ) { if( isFull( ) ) { cout << &quot;insert - Heap is full.&quot; << endl; return 0; } // Percolate up int hole = ++currentSize; for(; hole > 1 && x < array[hole/2 ]; hole /= 2) array[ hole ] = array[ hole / 2 ]; array[hole] = x; } http://ecomputernotes.com
Heap code in C++ template <class eType> void Heap<eType>::deleteMin( eType & minItem ) { if( isEmpty( ) ) { cout <<  &quot; heap is empty. “ << endl ; return; } minItem = array[ 1 ]; array[ 1 ] = array[ currentSize-- ]; percolateDown( 1 ); } http://ecomputernotes.com
Ad

Recommended

Computer notes - Build Heap
Computer notes - Build Heap
ecomputernotes
 
C workshop day 6
C workshop day 6
Mayank Agrawal
 
แผนการจัดการเรียนรู้ที่ ๓
แผนการจัดการเรียนรู้ที่ ๓
mathawee wattana
 
Influencias admon
Influencias admon
yolansir
 
Wap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
Practicas 1.4
Practicas 1.4
Angie Lp Mtz G
 
Raphaël and You
Raphaël and You
Trotter Cashion
 
Device Modeling of 3INPUT COMPARATOR using PSpice
Device Modeling of 3INPUT COMPARATOR using PSpice
Tsuyoshi Horigome
 
Tilting Google Maps and MissileLauncher
Tilting Google Maps and MissileLauncher
Tatsuhiko Miyagawa
 
Seaborn graphing present
Seaborn graphing present
Yilin Zeng
 
Exercicis selectivitat
Exercicis selectivitat
Jorge Belmonte Castro
 
AI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to hero
Gianluca Carucci
 
Vcs23
Vcs23
Malikireddy Bramhananda Reddy
 
Clock For My
Clock For My
shamalanamnam
 
Open Cv Tutorial Ii
Open Cv Tutorial Ii
Waris Songtantarak
 
TC7S08F PSpice Model (Free SPICE Model)
TC7S08F PSpice Model (Free SPICE Model)
Tsuyoshi Horigome
 
Sary
Sary
sarylozano
 
Advanced Topics in Haskell
Advanced Topics in Haskell
ikegami__
 
Sqlite
Sqlite
Mostafa Alinaghi Pour
 
Predictive Analytics Powered By Process Mining: It’s The Process, Stupid!
Predictive Analytics Powered By Process Mining: It’s The Process, Stupid!
Rising Media Ltd.
 
真っ黒Scheme
真っ黒Scheme
yadokari electric
 
Self Evaluation Test
Self Evaluation Test
Berk Soysal
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 17
computer notes - Data Structures - 17
ecomputernotes
 
computer notes - Data Structures - 7
computer notes - Data Structures - 7
ecomputernotes
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 26
computer notes - Data Structures - 26
ecomputernotes
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8
ecomputernotes
 

More Related Content

What's hot (14)

Tilting Google Maps and MissileLauncher
Tilting Google Maps and MissileLauncher
Tatsuhiko Miyagawa
 
Seaborn graphing present
Seaborn graphing present
Yilin Zeng
 
Exercicis selectivitat
Exercicis selectivitat
Jorge Belmonte Castro
 
AI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to hero
Gianluca Carucci
 
Vcs23
Vcs23
Malikireddy Bramhananda Reddy
 
Clock For My
Clock For My
shamalanamnam
 
Open Cv Tutorial Ii
Open Cv Tutorial Ii
Waris Songtantarak
 
TC7S08F PSpice Model (Free SPICE Model)
TC7S08F PSpice Model (Free SPICE Model)
Tsuyoshi Horigome
 
Sary
Sary
sarylozano
 
Advanced Topics in Haskell
Advanced Topics in Haskell
ikegami__
 
Sqlite
Sqlite
Mostafa Alinaghi Pour
 
Predictive Analytics Powered By Process Mining: It’s The Process, Stupid!
Predictive Analytics Powered By Process Mining: It’s The Process, Stupid!
Rising Media Ltd.
 
真っ黒Scheme
真っ黒Scheme
yadokari electric
 
Self Evaluation Test
Self Evaluation Test
Berk Soysal
 

Viewers also liked (20)

computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 17
computer notes - Data Structures - 17
ecomputernotes
 
computer notes - Data Structures - 7
computer notes - Data Structures - 7
ecomputernotes
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 26
computer notes - Data Structures - 26
ecomputernotes
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8
ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 24
computer notes - Data Structures - 24
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34
ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32
ecomputernotes
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18
ecomputernotes
 
computer notes - Data Structures - 27
computer notes - Data Structures - 27
ecomputernotes
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9
ecomputernotes
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1
ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 17
computer notes - Data Structures - 17
ecomputernotes
 
computer notes - Data Structures - 7
computer notes - Data Structures - 7
ecomputernotes
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 26
computer notes - Data Structures - 26
ecomputernotes
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8
ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 24
computer notes - Data Structures - 24
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 34
computer notes - Data Structures - 34
ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32
ecomputernotes
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18
ecomputernotes
 
computer notes - Data Structures - 27
computer notes - Data Structures - 27
ecomputernotes
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9
ecomputernotes
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1
ecomputernotes
 
Ad

Similar to computer notes - Data Structures - 25 (20)

LEC 8-DS ALGO(heaps).pdf
LEC 8-DS ALGO(heaps).pdf
MuhammadUmerIhtisham
 
Build Heap Step by Step
Build Heap Step by Step
Log(n) Academy
 
Heap Hand note
Heap Hand note
Abdur Rouf
 
Heaps
Heaps
IIUM
 
Lec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptx
IqraHanif27
 
Data Structures and Agorithm: DS 18 Heap.pptx
Data Structures and Agorithm: DS 18 Heap.pptx
RashidFaridChishti
 
05 heap 20161110_jintaeks
05 heap 20161110_jintaeks
JinTaek Seo
 
Complete binary tree and heap
Complete binary tree and heap
Nazir Ahmed
 
Heaps and tries power point this is an educational material
Heaps and tries power point this is an educational material
AymericTaylor
 
thisisheapsortpptfilewhichyoucanuseanywhereanytim
thisisheapsortpptfilewhichyoucanuseanywhereanytim
hamdardhamdard864
 
Heap sort
Heap sort
Mohd Arif
 
lecture 5
lecture 5
sajinsc
 
Heapsortokkay
Heapsortokkay
Remesha
 
Lec20
Lec20
Anjneya Varshney
 
10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues
SSE_AndyLi
 
Binary heap (Priority Queue).ppt
Binary heap (Priority Queue).ppt
Mano Arun
 
Heaps
Heaps
Hoang Nguyen
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
americanopticalscbe
 
Heaps
Heaps
pratmash
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
Build Heap Step by Step
Build Heap Step by Step
Log(n) Academy
 
Heap Hand note
Heap Hand note
Abdur Rouf
 
Heaps
Heaps
IIUM
 
Lec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptx
IqraHanif27
 
Data Structures and Agorithm: DS 18 Heap.pptx
Data Structures and Agorithm: DS 18 Heap.pptx
RashidFaridChishti
 
05 heap 20161110_jintaeks
05 heap 20161110_jintaeks
JinTaek Seo
 
Complete binary tree and heap
Complete binary tree and heap
Nazir Ahmed
 
Heaps and tries power point this is an educational material
Heaps and tries power point this is an educational material
AymericTaylor
 
thisisheapsortpptfilewhichyoucanuseanywhereanytim
thisisheapsortpptfilewhichyoucanuseanywhereanytim
hamdardhamdard864
 
lecture 5
lecture 5
sajinsc
 
Heapsortokkay
Heapsortokkay
Remesha
 
10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues
SSE_AndyLi
 
Binary heap (Priority Queue).ppt
Binary heap (Priority Queue).ppt
Mano Arun
 
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
Complete the classes shown below 1. The MinHeap Class Write necessa.pdf
americanopticalscbe
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
Ad

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30
ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
ecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating Data
ecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
ecomputernotes
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14
ecomputernotes
 
Computer notes - Controlling User Access
Computer notes - Controlling User Access
ecomputernotes
 
Computer notes - Using SET Operator
Computer notes - Using SET Operator
ecomputernotes
 
computer notes - Data Structures - 30
computer notes - Data Structures - 30
ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
ecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating Data
ecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
ecomputernotes
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14
ecomputernotes
 
Computer notes - Controlling User Access
Computer notes - Controlling User Access
ecomputernotes
 
Computer notes - Using SET Operator
Computer notes - Using SET Operator
ecomputernotes
 

Recently uploaded (20)

10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
The Growing Value and Application of FME & GenAI
The Growing Value and Application of FME & GenAI
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
The Growing Value and Application of FME & GenAI
The Growing Value and Application of FME & GenAI
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 

computer notes - Data Structures - 25

  • 1. Class No.25 Data Structures http://ecomputernotes.com
  • 2. BuildHeap The general algorithm is to place the N keys in an array and consider it to be an unordered binary tree. The following algorithm will build a heap out of N keys. for( i = N/2; i > 0; i-- ) percolateDown(i); http://ecomputernotes.com
  • 3. BuildHeap i = 15/2 = 7 65 19 21 14 24 26 13 15 68 16 65 21 19 26 14 16 68 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 12 15 5 70 12 i  i Why I=n/2? http://ecomputernotes.com
  • 4. BuildHeap i = 15/2 = 7 65 19 21 14 24 26 13 15 12 16 65 21 19 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 68 15 5 70 68 i  i http://ecomputernotes.com
  • 5. BuildHeap i = 6 65 19 21 14 24 26 13 15 12 16 65 21 19 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 5 13 70 14 68 15 5 70 68 i  i http://ecomputernotes.com
  • 6. BuildHeap i = 5 65 5 21 14 24 26 13 15 12 16 65 21 5 26 14 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i  i http://ecomputernotes.com
  • 7. BuildHeap i = 4 65 5 14 21 24 26 13 15 12 16 65 14 5 26 21 16 12 13 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i  i http://ecomputernotes.com
  • 8. BuildHeap i = 3 65 5 14 21 24 13 26 15 12 16 65 14 5 13 21 16 12 26 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 32 32 12 15 4 19 13 70 14 68 15 19 70 68 i  i http://ecomputernotes.com
  • 9. BuildHeap i = 2 65 16 14 21 24 13 26 15 12 32 65 14 16 13 21 32 12 26 24 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 31 31 11 5 5 12 15 4 19 13 70 14 68 15 19 70 68 i  i http://ecomputernotes.com
  • 10. BuildHeap i = 1 65 16 14 21 31 24 26 15 12 32 65 14 16 24 21 32 12 26 31 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 13 13 11 5 5 12 15 4 19 13 70 14 68 15 19 70 68 i  i http://ecomputernotes.com
  • 11. BuildHeap Min heap 5 16 14 21 31 24 26 15 65 32 5 14 16 24 21 32 65 26 31 15 1 2 3 5 6 7 8 9 10 11 12 13 14 0 1 2 3 7 6 5 4 8 9 10 13 13 11 12 12 12 15 4 19 13 70 14 68 15 19 70 68 http://ecomputernotes.com
  • 12. Other Heap Operations decreaseKey(p, delta) : lowers the value of the key at position ‘p’ by the amount ‘delta’. Since this might violate the heap order, the heap must be reorganized with percolate up (in min heap) or down (in max heap). increaseKey(p, delta) : opposite of decreaseKey. remove(p) : removes the node at position p from the heap. This is done by first decreaseKey(p, ) and then performing deleteMin(). http://ecomputernotes.com
  • 13. Heap code in C++ template <class eType> class Heap { public: Heap( int capacity = 100 ); void insert( const eType & x ); void deleteMin( eType & minItem ); const eType & getMin( ); bool isEmpty( ); bool isFull( ); int Heap<eType>::getSize( ); http://ecomputernotes.com
  • 14. Heap code in C++ private: int currentSize; // Number of elements in heap eType* array; // The heap array int capacity; void percolateDown( int hole ); }; http://ecomputernotes.com
  • 15. Heap code in C++ #include &quot;Heap.h“ template <class eType> Heap<eType>::Heap( int capacity ) { array = new etype[capacity + 1]; currentSize=0; } http://ecomputernotes.com
  • 16. Heap code in C++ // Insert item x into the heap, maintaining heap // order. Duplicates are allowed. template <class eType> bool Heap<eType>::insert( const eType & x ) { if( isFull( ) ) { cout << &quot;insert - Heap is full.&quot; << endl; return 0; } // Percolate up int hole = ++currentSize; for(; hole > 1 && x < array[hole/2 ]; hole /= 2) array[ hole ] = array[ hole / 2 ]; array[hole] = x; } http://ecomputernotes.com
  • 17. Heap code in C++ template <class eType> void Heap<eType>::deleteMin( eType & minItem ) { if( isEmpty( ) ) { cout << &quot; heap is empty. “ << endl ; return; } minItem = array[ 1 ]; array[ 1 ] = array[ currentSize-- ]; percolateDown( 1 ); } http://ecomputernotes.com

Editor's Notes

  • #3: Star of lecture 31
  • #7: End of lecture 30
  • #18: End of lecture 31, start of 32